<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/9/23
  Time: 21:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>跨域请求</title>
    <script src="/js/jquery-2.1.1.min.js"></script>
    <script>
        $(function () {
            $("#btn").click(function () {
                /*http://localhost:8080/cross.jsp 与下面的网址不是跨域请求*/
                /*$.get("http://localhost:8080/m3",function (data) {
                    console.log(data);
                })*/
                /*http://localhost:8080/cross.jsp 与下面的网址是跨域请求 （域名不同） ，请求发送失败
                * 报错：Access to XMLHttpRequest at 'http://127.0.0.1:8080/m3' from
                * origin 'http://localhost:8080' has been blocked by CORS policy:
                * No 'Access-Control-Allow-Origin' header is present on the requested resource.
                jquery-2.1.1.min.js:4
                * GET http://127.0.0.1:8080/m3 net::ERR_FAILED 200*/
                /*在控制器加上@CrossOrigin(),就可以发送跨域请求   括号里是可以跨域发送的请求地址*/
                $.get("http://127.0.0.1:8080/m3",function (data) {
                    console.log(data);
                })

            })
        })
    </script>
</head>
<body>
<button id="btn">异步请求</button>
</body>
</html>
